import {request} from '@/plugins/axios'
import ApiPath from '@/utils/api_paths'
import qs from "qs";

export function list(query) {
    return request({
        url: ApiPath.role,
        method: 'get',
        params: query
    })
}

export function add(data) {
    return request({
        url: ApiPath.role,
        method: 'post',
        data
    })
}

export function del(id) {
    return request({
        url: ApiPath.role + '/' + id,
        method: 'delete'
    })
}

export function update(data) {
    return request({
        url: ApiPath.role + '/' + data.roleId,
        method: 'put',
        data
    })
}

export function get(id) {
    return request({
        url: ApiPath.role + '/' + id,
        method: 'get'
    })
}

export function menuTree() {
    return request({
        url: ApiPath.auth,
        method: 'get'
    })
}

export function roleMenus(roleName) {
    return request({
        url: ApiPath.auth + '/' + roleName,
        method: 'get'
    })
}

export function auth(data) {
    return request({
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        url: ApiPath.auth,
        method: 'post',
        data,
        transformRequest: [function (data) {
            return qs.stringify(data);
        }]
    })
}
